package com.kangfu.api.controller;

import java.util.List;

import com.kangfu.api.interceptor.AuthorizationInterceptor;
import com.kangfu.api.service.IArticleService;
import com.kangfu.common.annotation.IgnoreAuth;
import com.kangfu.common.model.AjaxResult;
import com.kangfu.db.model.vo.ArticleVo;
import com.kangfu.db.model.vo.MainArticleVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/article")
public class ArticleController
{
    @Autowired
    private IArticleService articleService;

    /**
     * 查询文章列表
     */
    @GetMapping("/list")
    public AjaxResult list(@RequestAttribute(AuthorizationInterceptor.LOGIN_USER_ID) int userId, @RequestParam(name = "page", defaultValue = "1") int page) {
        List<ArticleVo> list = articleService.selectArticleList(userId, page);
        return AjaxResult.success(list);
    }

    @GetMapping("/main")
    public AjaxResult main(@RequestAttribute(AuthorizationInterceptor.LOGIN_USER_ID) int userId) {
        List<MainArticleVo> list = articleService.selectMainArticle(userId);
        return AjaxResult.success(list);
    }

    /**
     * 获取文章详细信息
     */
    @GetMapping("/info")
    public AjaxResult getInfo(@RequestAttribute(AuthorizationInterceptor.LOGIN_USER_ID) int userId, @RequestParam(name = "id", defaultValue = "0") int id)
    {
        return AjaxResult.success(articleService.selectArticleById(userId, id));
    }

}
